package com.learning.jquizenglish.screen.doquiz;

import java.util.ArrayList;

import android.content.Context;

import com.learning.jquizenglish.JQuizAppConfig;
import com.learning.jquizenglish.model.JQuizRequestModel;
import com.learning.jquizenglish.model.QuestionModel;
import com.learning.jquizenglish.model.SaveScoreData;
import com.learning.jquizenglish.network.JQuizEnglishApi;
import com.learning.jquizenglish.network.JQuizEnglishApi.AppType;
import com.learning.jquizenglish.network.JQuizEnglishApi.Level;
import com.learning.jquizenglish.network.JQuizEnglishApi.QuestionType;

public class DoQuizSession {

	private static DoQuizSession INSTANCE = null;
	private Level questionLevel;
	private QuestionType questionType;
	private ArrayList<QuestionModel> listQuestions;
	
	public static DoQuizSession getInstance(){
		if (INSTANCE == null) {
			INSTANCE = new DoQuizSession();
		}
		return INSTANCE;
	}

	public Level getQuestionLevel() {
		return questionLevel;
	}

	public void setQuestionLevel(Level questionLevel) {
		this.questionLevel = questionLevel;
	}

	public ArrayList<QuestionModel> getListQuestions() {
		return listQuestions;
	}

	public void setListQuestions(ArrayList<QuestionModel> listQuestions) {
		this.listQuestions = listQuestions;
	}
	
	public QuestionType getQuestionType() {
		return questionType;
	}

	public void setQuestionType(QuestionType questionType) {
		this.questionType = questionType;
	}

	SaveScoreData data;
	public JQuizRequestModel getRequestSaveScore(Context context){
		data = SaveScoreData.createSaveScoreInfo(listQuestions);
		AppType appType = AppType.GRAMMAR;
		if (JQuizAppConfig.IS_LISTENING_APP) {
			appType = AppType.LISTENING;
		}
		JQuizRequestModel model = JQuizEnglishApi.getRequestSaveScore(context,questionLevel, 
				data.score, data.percent, data.jsonAnswer, appType);
		return model;
	}
	
	public SaveScoreData getScoreData(){
		return data;
	}
	
	public boolean isAnswerAllQuestion(){
		if (listQuestions!=null) {
			int size = listQuestions.size();
			for (int i = 0; i < size; i++) {
				if (!listQuestions.get(i).isAnswered) {
					return false;
				}
			}
		}else{
			return false;
		}
		return true;
	}
	
	public void clearSession(){
		questionType = null;
		questionLevel = null;
		listQuestions = null;
	}
	
}
